<template>
  
  <el-row type="flex" class="row-bg wrapper" justify="center" align="middle" >
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="pass">
        <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
          <el-button type="primary" @click="onSubmit">登陆</el-button>
          <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </el-row>
</template>

<script>
export default {
  data(){
    return {
      form:{
        username:'',
        password:''
      }
    }
  },
  methods:{
    onSubmit(){
      this.$axios({
        url:'/login',
        method:'post',
        data:this.form
      }).then(res=>{
        // console.log(res.data);
        const {message}=res.data
        if(message=='登录成功'){
          // console.log(111)
          localStorage.setItem('user',JSON.stringify(res.data.data.user));
          localStorage.setItem('token',res.data.data.token);
           this.$router.push({path:'/'})
        }
      })
     
    }
  }
}
</script>

<style lang="less" scoped>
  .wrapper{
    width: 100%;
    position: absolute;
    top: 0;
    bottom: 0;
  }
</style>